﻿<!DOCTYPE html>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>列表</title>
    <link href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui.min.css" rel="stylesheet" />
    <link href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui-append.css" rel="stylesheet" />
    <style type="text/css">
        .ms-controller{visibility:hidden;}
    </style>

</head>
<body ms-controller="listview" class="ms-controller">
    <div class="sui-container" style="width:98%">
        <div class="sui-form form-inline" style="padding-top:5px;">
            <select class="input-large input-xfat" ms-change="GetLIST()" ms-duplex="Type1">
                <option value="">请选择分类</option>
                <option ms-repeat-el="TypeList" ms-attr-value="el.ID">{{el.TypeName}}</option>
            </select>
            <input type="text" ms-duplex="searchkey" placeholder="关键字搜索" class="input-large input-xfat"/>
            <a class="sui-btn btn-large btn-primary" style="margin-left:10px;" ms-click="GetLIST()">查询</a>
            <a style="margin-left:10px;" class="sui-btn btn-large btn-success" ms-click="ADD('')" ms-if="top.model.HasAuth('ADD')">添加</a>
        </div>

        <div ms-include-src="../list/{{FunCode}}.html?rdm={{rdm}}" data-include-rendered='render' style="padding-bottom:20px;">

        </div>
 

        <div id="pageDiv"></div>
        <div class="sui-form form-inline" style="margin-top:20px;">
            <div class="sui-msg msg-large msg-success">
                <div class="msg-con">总数据：{{total}}</div>
                <s class="msg-icon"></s>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="http://g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="http://g.alicdn.com/sj/dpl/1.5.1/js/sui.min.js"></script>
    <script src="https://cdn.bootcss.com/avalon.js/1.5.9/avalon.js"></script>
    <script src="/admin/js/ComFunJS.js?v=20180101"></script>
    <script type="text/javascript">
        var model = avalon.define({
            $id: "listview",
            searchkey: "",
            page: { pageindex: 1, pagesize: 10 },
            TypeList: [],
            Type1: "",
            ListData: [],
            total: 0,
            FunCode: ComFunJS.getQueryString("funcode"),
            PageCode: "",
            rdm: Math.random(),
            InfoType: ComFunJS.getQueryString("infotype", ""),
            ApiName: "",
            render: function () {

            },
            GetLIST: function () {
                model.page.pageindex = 1;
                model.ListData.clear();
                $.getJSON(model.ApiName, { pageindex: model.page.pageindex, pagesize: model.page.pagesize, key: model.searchkey, Type1: model.Type1 }, function (r) {
                    if (r.error == "") {
                        model.ListData = r.result;
                        model.total = r.total;

                        $("#pageDiv").pagination({  //分页容器
                            styleClass: ['sui-pagination'],  //分页样式
                            //showCtrl: false,
                            displayPage: 6,
                            itemsCount: r.total,
                            pageSize: model.page.pagesize,
                            onSelect: function (num) {
                                model.page.pageindex = num;
                                $.getJSON(model.ApiName, { pageindex: model.page.pageindex, pagesize: model.page.pagesize, key: model.searchkey, Type1: model.Type1 }, function (r) {
                                    model.ListData.clear();
                                    model.ListData = r.result;
                                })
                            }
                        })

                        $('#pageDiv').pagination('updateItemsCount', r.total, 1);
                    }
                })
            },
            ADD: function (el) {
                if (el) {
                    top.ComFunJS.winShowForm("/admin/base/add.html?funcode=" + model.FunCode + "&ID=" + el.ID + "&infotype=" + el.InfoType, "修改");
                } else {
                    top.ComFunJS.winShowForm("/admin/base/add.html?funcode=" + model.FunCode + "&infotype=" + model.InfoType, "添加");
                }
            },
            DEL: function (el) {
                if (el) {
                    top.ComFunJS.winShowConfirm("<span style='color:red;'>确定要删除吗?<span>", function () {
                        $.getJSON("/adapi/" + model.FunCode + "/del/" + el.ID, function (r) {
                            if (r.error == "") {
                                top.ComFunJS.winShowMsg("删除成功");
                                model.ListData.remove(el);
                            }
                        })
                    })
                }
            },
            GetTypeList: function () {
                if (model.FunCode == "advert") {
                    model.TypeList = [
                        { "ID": "1", "TypeName": "首页" },
                        { "ID": "2", "TypeName": "分类视频" },
                        { "ID": "3", "TypeName": "华豫学院" },
                        { "ID": "4", "TypeName": "热门活动" },
                        { "ID": "5", "TypeName": "真品馆" }
                    ];
                } else {
                    $.getJSON("/adapi/base/catelist/" + model.InfoType, function (r) {
                        model.TypeList = r.result;
                    })
                }

            },
            SetShelf: function (el) {
                $.getJSON("/adapi/info/shelf/" + el.ID, function (r) {
                    if (r.error == "") {
                        el.IsShelf = el.IsShelf == 1 ? 0 : 1;
                    }
                })
            }
        });

        avalon.ready(function () {
            model.PageCode = "../list/" + model.FunCode + ".html";
            model.ApiName = "/adapi/" + model.FunCode + "/list";
            if (model.FunCode == "info") {
                model.ApiName += "/" + model.InfoType;
            }
            model.GetLIST();
            model.GetTypeList();
        })

    </script>

</body>

</html>


